﻿using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Trippy.CollidableGameComponents;
using Trippy.CollidableGameComponents.Agents;
using Trippy.Levels;

namespace Trippy.Abilities
{
    class Invincibility : Ability
    {
        protected float activeTime; //time this ability is active before disappearing.

        public Invincibility(Level level, float t)
            : base(level)
        {
            name = "Invincibility";
            icon = CurrentLevel.Game.Content.Load<Texture2D>("Sprites/Ability Icons/invincibility");
            activeTime = t;
        }

        public override void OnAdd()
        {
            State = AbilityState.Active;
            SetTimer(activeTime);
            CurrentLevel.Hero.Sprite.Tint = Color.Gold;
        }

        public override void OnRemove()
        {
            CurrentLevel.Hero.Sprite.Tint = Color.White;
            base.OnRemove();
        }

        protected override void OnTimer()
        {
            CurrentLevel.Hero.RestoreAbility();
        }

        public override bool OnDie(Hero.MannerOfDeath d)
        {
            if (d != Hero.MannerOfDeath.Falling 
                && State == AbilityState.Active)
                return false; //you can't die while this is on you.
            else
            {
                CurrentLevel.Hero.RemoveAbility();
                return true; //won't save you from falling death.
            }
        }
    }

    class ActivateableInvincibility : Invincibility
    {
        public ActivateableInvincibility(Level level, float t)
            : base(level, t)
        {
        }

        public override void OnAdd()
        {
            State = AbilityState.Available;
        }

        public override void OnActivate()
        {
            CurrentLevel.Hero.Sprite.Tint = Color.Gold;
            State = AbilityState.Active;
            SetTimer(activeTime);
            base.OnActivate();
        }
    }

    class PassiveInvincibility : Invincibility
    {
        public PassiveInvincibility(Level level, float t)
            : base(level, t)
        {
        }

        public override void OnAdd()
        {
            State = AbilityState.Passive;
        }

        public override bool OnDie(Hero.MannerOfDeath d)
        {
            if (d != Hero.MannerOfDeath.Falling)
            {
                CurrentLevel.Hero.RestoreAbility(); //to set previous ability to before this one.
                CurrentLevel.Hero.CurrentAbility = new Invincibility(CurrentLevel, activeTime);
                return false;
            }
            else
            {
                CurrentLevel.Hero.RemoveAbility();
                return true; //won't save you from falling death.
            }
        }
    }
}
